/**
 * @type import('@vue/cli-service').ServicePlugin
 */
module.exports = api => {
  api.configureDevServer((app, a) => {
    const jsonServer = require('json-server')
    const path = require('path')
    const express = require('express')
    const logger = require('./logger')

    app.use(express.json())
    app.use(express.urlencoded({
      extended: true
    }))
    app.use(logger('/api'))


    const _router = app._router
    const router = jsonServer.router(path.join(__dirname, 'data.json'))

    _router.post('/checkout', (req, res) => {
      res.status(200).json({
        success: Math.random() > 0.5
      })
    })

    app.use('/api', [router, _router])

  })
}